package com.cq.hd.admin.controller;

import com.alibaba.fastjson.JSONObject;
import com.cq.hd.admin.annotation.RequiresPermissionsDesc;
import com.cq.hd.common.pagination.Page;
import com.cq.hd.common.response.Result;
import com.cq.hd.member.api.TbMerchantApi;
import com.cq.hd.member.api.dto.MerchantPageDto;
import com.cq.hd.member.api.dto.RelationBusinessPageDto;
import com.cq.hd.member.api.vo.AdminMerchantPageVo;
import com.cq.hd.member.api.vo.RelationBusinessPageVo;
import com.cq.hd.member.api.vo.MerchantPageVo;
import com.cq.hd.system.api.HfApi;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiResponse;
import lombok.extern.slf4j.Slf4j;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * <p>
 * 商户表 前端控制器
 * </p>
 *
 * @author mYunYu
 * @since 2023-11-21
 */
@Api(tags = "商户相关接口")
@Slf4j
@RestController
@RequestMapping("/merchant")
public class TbMerchantController {

    private TbMerchantApi merchantApi;

    @Autowired
    private HfApi hfApi;

    @Autowired
    public void setMerchantApi(TbMerchantApi merchantApi) {
        this.merchantApi = merchantApi;
    }

    @ApiOperation(value = "商户列表")
    @ApiImplicitParam(name = "merchantPageDto", value = "实体", paramType = "query", dataType = "MerchantPageDto")
    @ApiResponse(response = MerchantPageVo.class, code = 200, message = "接口返回对象参数")
    @RequiresPermissions("merchant:merchant:list")
    @RequiresPermissionsDesc(menu = {"商户管理", "商户管理"}, button = "查询")
    @GetMapping("/page")
    public Result<Page<MerchantPageVo>> pageMerchant(MerchantPageDto merchantPageDto) {
        return merchantApi.pageMerchant(merchantPageDto);
    }

    @ApiOperation(value = "商户详情")
    @ApiImplicitParam(name = "id", value = "id", required = true, paramType = "query", dataType = "Long")
    @ApiResponse(response = AdminMerchantPageVo.class, code = 200, message = "接口返回对象参数")
    @RequiresPermissions("merchant:merchant:detail")
    @RequiresPermissionsDesc(menu = {"商户管理", "商户管理"}, button = "详情")
    @GetMapping("/details")
    public Result<AdminMerchantPageVo> details(Long id) {
        return merchantApi.details(id);
    }

    @ApiOperation(value = "关联商家列表")
    @ApiImplicitParam(name = "relationBusinessPageDto", value = "实体", paramType = "query", dataType = "RelationBusinessPageDto")
    @ApiResponse(response = RelationBusinessPageVo.class, code = 200, message = "接口返回对象参数")
    @RequiresPermissions("merchant:merchant:relationBusiness")
    @RequiresPermissionsDesc(menu = {"商户管理", "商户管理"}, button = "关联商家列表")
    @GetMapping("/pageRelationBusiness")
    public Result<Page<RelationBusinessPageVo>> pageRelationBusiness(RelationBusinessPageDto relationBusinessPageDto) {
        return merchantApi.pageRelationBusiness(relationBusinessPageDto);
    }

    @ApiOperation(value = "汇付余额查询")
    @ApiImplicitParam(name = "hfId", value = "hfId", required = true, paramType = "query", dataType = "String")
    @ApiResponse(response = JSONObject.class, code = 200, message = "接口返回对象参数")
    @RequiresPermissionsDesc(menu = {"商户管理", "商户管理"}, button = "详情")
    @GetMapping("/acctBalanceQuery")
    public Result<JSONObject> acctBalanceQuery(String hfId) {
        return hfApi.acctBalanceQuery(hfId);
    }
}
